Skip to content

insert Image via url#24

Open
sayeham wants to merge 5 commits into
developfrom
HamzaAlam/feature/image-upload
Open

insert Image via url#24
sayeham wants to merge 5 commits into
developfrom
HamzaAlam/feature/image-upload

Conversation

@sayeham

@sayeham sayeham commented Feb 28, 2021

Copy link
Copy Markdown
Collaborator
  • Insert Image View url
  • withImage plugin to change position of url
  • serialization and deserialzation updated
  • withBreak plugin (override the insertBreak function)
    Data structure to save into DB:
{
    block: {
      _id: '5',
      type: 'image',
      properties: {
        document: [
          {
            text: '',
            properties: [
              'https://repository-images.githubusercontent.com/125159715/61f2ee00-865a-11e9-8ce5-f7028c561633',
            ],
          },
        ],
      },
    },
  },

Slate internal data structure:

{
"id":"5","type":"image",
"children":[{"text":""}],
"url":["https://repository-images.githubusercontent.com/125159715/61f2ee00-865a-11e9-8ce5-f7028c561633"]
}

image
image

@Fahad-Mahmood Fahad-Mahmood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't move the cursor to the bottom of the image in order to add more text.

Screenshot (838)

@sayeham

sayeham commented Mar 2, 2021

Copy link
Copy Markdown
Collaborator Author

I can't move the cursor to the bottom of the image in order to add more text.

Screenshot (838)

for that you can change position of image by dragging and dropping to the upper nodes but it has internal bug of duplication
image

Comment on lines +17 to +33
export const InsertImageButton: (props: InsertImageButtonProps) => JSX.Element = ({ icon, iconColor = '#ffffff' }) => {
const editor = useSlate();
return (
<Button
onMouseDown={(event) => {
event.preventDefault();
const url = window.prompt('Enter the URL of the image:');
if (!url) return;
insertImage(editor, url);
}}
>
<Icon reversed active={false} svg={icon} color={iconColor}>
image
</Icon>
</Button>
);
};

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

insert Image via url logic and button

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for that you can change position of image by dragging and dropping to the upper nodes but it has internal bug of duplication

@Hamzaalam we have to resolve this issue, there should be some way to add some text to the bottom of the image, especially if the last node is an image node. Also, moving the image doesn't remove it.

The best way would be to add an empty node on either enter key or down key press.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fahad-Mahmood inserting the empty block at the bottom of image is working on Enter , just need to trace the cursor and only triggers this at the end of the line.

Comment thread src/deserialize/index.ts
Comment on lines +59 to +62
if (type === 'image' && block.properties) {
return { id: block._id, type, children, url: block.properties.document[0].properties };
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

deserialization (DB to slate)

Comment thread src/plugins/Element.tsx
Comment on lines +45 to +53
case `image`:
return (
<div {...attributes}>
<div contentEditable={false}>
<Image src={element.url} />
</div>
{children}
</div>
);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image element to render the image inside of slate editor

Comment on lines +82 to +87
export const Image = styled.img`
display: block;
max-width: 100%;
max-height: 20em;
padding: 4px 0px 0px 20px;
`;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image Styled component

Comment on lines +3 to +11
const withImages = (editor: ReactEditor) => {
const { isVoid } = editor;
const localEditor = editor;
localEditor.isVoid = (element) => {
return element.type === 'image' ? true : isVoid(element);
};
return localEditor;
};
export default withImages;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Image plugin to support he drag and drop of existing image

Comment thread src/serialize/index.tsx
Comment on lines +41 to +46
let properties = [];
if (textType === 'image') {
properties.push(paragraphNode.url);
} else {
properties = getParagraphProperties(childNodes);
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serialization logic (slate to DB structure)

@sayeham sayeham requested a review from ammarjussa March 2, 2021 08:32

@ammarjussa ammarjussa left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works fine!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants